define(['core/ModuleResolver',"Router","/core/ApplicationService"],function(require, exports, module){
    var deps = ['ModuleResolver','ApplicationService','ui.bootstrap','ngGrid'],
        router = require("Router").restricted,
        service = require("core/ApplicationService"),
        moduleResolver = require("core/ModuleResolver"),

        adminPanel = angular.module('AdminPanel',deps);

    adminPanel.config(['$routeProvider' ,'moduleResolverProvider', '$locationProvider',
        function($routeProvider ,moduleResolverProvider ,$locationProvider){
            var resolve = moduleResolverProvider.resolve;

            $.each(router ,function(index ,route){
                //console.log(arguments);
                if(route["url"] == "otherwise"){
                    $routeProvider.otherwise({
                        redirectTo: route["redirectTo"]
                    });
                    return;
                }
                //console.log(route.options);
                $routeProvider.when(route.url,resolve(route.options));
            });

            $locationProvider.html5Mode(true);

	    }
    ]);
    adminPanel.run(['$rootScope','$location','ServicesProvider',
        function($rootScope ,$location ,servicesProvider ){
            //console.log($loadOnDemandProvider);
            //console.log(servicesProvider);
            var responseModel = servicesProvider.global.get();
            $rootScope.config = responseModel;
            //$rootScope.message = {type : 'error' ,text:'ok'};
            $rootScope.closeAlert = function(){
                $rootScope.message = null;
            }

            var navEl = angular.element('.nav.nav-list.nav-stacked');
            var previousNavEl = '';
            $rootScope.$on('$routeChangeSuccess', function(scope, next, current){
                if(previousNavEl){
                    previousNavEl.removeClass('active');
                }
                navEl.find("[href=\"" + $location.path() + "\"]").parent().addClass("active");
                previousNavEl = navEl.find("[href=\"" + $location.path() + "\"]").parent();
            });
	    }
    ]);
    return adminPanel;
});